﻿using System.Collections.Generic;
using NHibernate;

namespace Genesis.Infrastructure.Persistence
{

    using Genesis.Infrastructure.Domain;
    using Genesis.Infrastructure.Domain.Persistence;
    using Genesis.Infrastructure.Persistence.Providers;

    public class Repository<T, I> : IRepository<T, I> where T : Entity<I>
    {

        protected ISession Session
        {

            get { return SessionProvider.Current; }

        }

        public IEnumerable<T> Select()
        {

            return Session.CreateCriteria<T>().Future<T>();

        }

        public T SelectById(I id)
        {

            return Session.Get<T>(id);

        }

        public void Insert(T entity)
        {

            Session.Save(entity);

        }

        public void Update(T entity)
        {

            Session.Update(entity);

        }

        public void Delete(T entity)
        {

            Session.Delete(entity);

        }

    }

}